<template>
  <div>
    <div v-if="!applyCardList">
      <Error></Error>
    </div>
    <div v-if="applyCardList">
      <div class="inquireDiv">
        <p>
          <label><span>商户号：</span>
            <el-input v-model="form.mer_no" placeholder="请输入商户号"></el-input>
          </label>
          <label><span>商户名：</span>
            <el-input v-model="form.mer_name" placeholder="请输入商户名"></el-input>
          </label>
          <label><span>订单号：</span>
            <el-input v-model="form.order_on" placeholder="请输入订单号"></el-input>
          </label>
        </p>
        <p style="margin-top: 20px">
          <label><span>订单状态：</span>
            <el-select v-model="form.status" placeholder="请选择状态">
              <el-option v-for="(item,key,index) in cardOrderStatus" :label="item" :value="key"
                         :key="index"></el-option>
            </el-select>
          </label>
          <label><span>开始时间：</span>
            <el-date-picker
              v-model="form.start_time"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="请选择日期">
            </el-date-picker>
          </label>
          <label><span>结束时间：</span>
            <el-date-picker
              v-model="form.end_time"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="请选择日期">
            </el-date-picker>
          </label>
          <el-button type="primary" @click="examineFn" style="float: right">查 询</el-button>
        </p>

      </div>
      <div class="tableDiv" v-loading="loading" style="width: 100%">
        <el-row>
          <el-table
            :cell-class-name="addClass"
            :data="tableData"
            border
            stripe
            style="width: 100%"
          >
            <el-table-column
              type="index"
              align="center"
              min-width="40"
              width="48"
              label="#">
            </el-table-column>
            <el-table-column
              prop="aco_order_on"
              align="center"
              min-width="80"
              width="190"
              label="订单号">
            </el-table-column>
            <el-table-column
              prop="mer_no"
              align="center"
              min-width="80"
              width="128"
              label="商户号">
            </el-table-column>
            <el-table-column
              prop="mer_name"
              align="center"
              width="80"
              label="商户名称">
            </el-table-column>
            <el-table-column
              prop="aco_info"
              align="center"
              width="170"
              label="用户信息">
            </el-table-column>
            <el-table-column
              prop="aco_bank_name"
              align="center"
              width="150"
              label="银行卡信息">
            </el-table-column>
            <el-table-column
              prop="aco_status_test"
              align="center"
              width="85"
              label="订单状态">
            </el-table-column>
            <el-table-column
              prop="aco_create_time"
              align="center"
              sortable
              width="182"
              label="创建时间"
            >
            </el-table-column>
            <af-table-column
              label="操作"
              align="center">
              <template slot="header" slot-scope="scope">
                <div class="el-table-header">
                  <el-button type="primary" @click.native.prevent="addInformation" style="visibility: hidden">添加
                  </el-button>
                </div>
              </template>
              <template slot-scope="scope">
                <el-button v-show="scope.row.mbc_status == '1'"
                           v-if="updateConfig"
                           @click.native.prevent="deleteRow(scope.$index,tableData,2)"
                           type="danger"
                           size="small">
                  禁用
                </el-button>
                <el-button v-show="scope.row.mbc_status !== '1'"
                           v-if="updateConfig"
                           @click.native.prevent="deleteRow(scope.$index,tableData,1)"
                           type="success"
                           size="small">
                  启用
                </el-button>
                <el-button v-show="scope.row.wh_status == '2'"
                           v-if="queryOrderSend"
                           @click.native.prevent="resendRow(scope.$index,tableData)"
                           type="primary"
                           size="small">
                  查询重发
                </el-button>
              </template>
            </af-table-column>
          </el-table>
          <el-col :span="24">
            <div class="block" v-if="total">
              <el-pagination
                @current-change="handleCurrentChange"
                :current-page="currentPage"
                :page-size="10"
                layout="total, prev, pager, next"
                :total="total">
              </el-pagination>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
  </div>
</template>

<script>
  import Error from '../errorPage/errorPage401'

  export default {
    data() {
      return {
        mid: '',
        loading: true,
        currentPage: '',
        form: {
          mer_no: '',
          order_on: '',
          start_time: '',
          end_time: '',
          status: '',
          mer_name: ''
        },
        tableData: [],
        total: '',
        updateConfig: false,
        queryOrderSend: false,
        cardOrderStatus: {},
        applyCardList: false,
      }
    },
    methods: {
      //初始化
      initFn: function (page) {
        this.form.end_time = this.form.end_time == null ? '' : this.form.end_time;
        this.form.start_time = this.form.start_time == null ? '' : this.form.start_time;
        let data = {
          page: page,
          mer_no: this.form.mer_no,
          order_on: this.form.order_on,
          start_time: this.form.start_time,
          end_time: this.form.end_time,
          status: this.form.status,
          mer_name: this.form.mer_name,
        };
        let str = this.encryptionAesRsa(data);
        let encryptData = str.split('%$#@zjt@#$%')[0];
        let encryptKey = str.split('%$#@zjt@#$%')[1];
        let incomData = {
          map: 'admin_apply_list',
          plum_session_api: localStorage.getItem('token'),
          encryptData: encryptKey,
          encryptKey: encryptData
        };
        this.$http.post('', incomData).then((data) => {
          if (data.ec == 200) {
            this.loading = false;
            this.total = Number(data.data.count);
            this.currentPage = Number(data.data.page);
            this.tableData = data.data.list;
            this.cardOrderStatus = data.data.card_order_status;
          } else if (data.ec == 401) {
            this.$message.error(data.em);
            setTimeout(() => {
              this.exitLogin();
            }, 1500)
          } else {
            this.$message.error(data.em);
          }
        }).catch((err) => {
          this.$message.error('error!');
        })
      },
      //查询
      examineFn: function () {
        this.initFn(1)
      },
      //列变色
      addClass({row, column, rowIndex, columnIndex}) {
        if (columnIndex === 4) {
          return 'cell-blue'
        }
      },
      //点击分页
      handleCurrentChange(val) {
        this.$router.replace({
          path: this.$route.path,
          query: {
            page: val,
          }
        });
        this.loading = true;
        this.initFn(val);
      },
      // 禁用/启用按钮
      deleteRow(index, row, status) {
        let str = '';
        if (status == 1) {
          str = '此操作将启用该用户, 是否继续?'
        } else {
          str = '此操作将禁用该用户, 是否继续?'
        }
        this.$confirm(str, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.mid = row[index].mbc_id;
          let data = {
            mbc_id: this.mid,
            status: status
          };
          let str = this.encryptionAesRsa(data);
          let encryptData = str.split('%$#@zjt@#$%')[0];
          let encryptKey = str.split('%$#@zjt@#$%')[1];
          let incomData = {
            map: 'admin_mer_config_status',
            plum_session_api: localStorage.getItem('token'),
            encryptData: encryptKey,
            encryptKey: encryptData
          };
          this.$http.post('', incomData).then((data) => {
            if (data.ec == 200) {
              this.$message.success(data.em);
              this.initFn(this.currentPage)
            } else if (data.ec == 401) {
              this.$message.error(data.em);
              setTimeout(() => {
                this.exitLogin();
              }, 1500)
            } else {
              this.$message.error(data.em);
            }
          }).catch((err) => {
            this.$message.error('error!');
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消操作'
          });
        });
      },
      //  查询重发
      resendRow(index, row) {
        this.plumAxios('admin_apply_query', {
          order_id: row[index].aco_id
        }, (data) => {
          if (data.ec == 200) {
            this.$message.success(data.em);
            this.initFn(this.currentPage)
          } else if (data.ec == 401) {
            this.$message.error(data.em);
            setTimeout(() => {
              this.exitLogin();
            }, 1500)
          } else {
            this.$message.error(data.em);
          }
        });

        // let data = {
        //   order_id: row[index].aco_id
        // };
        // let str = this.encryptionAesRsa(data);
        // let encryptData = str.split('%$#@zjt@#$%')[0];
        // let encryptKey = str.split('%$#@zjt@#$%')[1];
        // let incomData = {
        //   map: 'admin_apply_query',
        //   plum_session_api: localStorage.getItem('token'),
        //   encryptData: encryptKey,
        //   encryptKey: encryptData
        // };
        // this.$http.post('', incomData).then((data) => {
        //   if (data.ec == 200) {
        //     this.$message.success(data.em);
        //     // this.initFn(this.currentPage)
        //   } else if (data.ec == 401) {
        //     this.$message.error(data.em);
        //     setTimeout(() => {
        //       this.exitLogin();
        //     }, 1500)
        //   } else {
        //     this.$message.error(data.em);
        //   }
        // }).catch((err) => {
        //   this.$message.error('error!');
        // });

      }
    },
    mounted() {
      this.currentPage = this.$route.query.page ? this.$route.query.page : 1;
      this.initFn(this.currentPage);
      // 按钮权限
      let buttonMenu = localStorage.getItem('buttonMenu');
      buttonMenu = this.edecryptButton(buttonMenu);
      if (buttonMenu.indexOf('queryOrderSend') !== -1) {
        this.queryOrderSend = true
      }
      //页面权限
      if (buttonMenu.indexOf('applyCardList') !== -1) {
        this.applyCardList = true
      }
    },
    components: {
      Error
    }
  }
</script>

<style scoped>
  .inquireDiv {
    padding: 30px;
    background: #ffffff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04)
  }

  .inquireDiv label {
    display: inline-block;
    margin-left: 50px;
  }

  .inquireDiv label span {
    width: 80px;
    display: inline-block;
  }

  .inquireDiv .el-input {
    width: 220px;
  }

  .tableDiv {
    margin-top: 20px;
  }

  .el-col {
    border-radius: 4px;
    height: 75px;
    background-color: #fff;
  }

  .tableDiv >>> .el-pagination {
    height: 30px;
    line-height: 30px;
    margin-top: 25px;
    text-align: center;
  }

  .tableDiv >>> .cell-blue {
    color: #F56C6C !important;
  }

  .drawerDiv {
    width: 100%;
    height: calc(90vh);
    padding: 20px;
    overflow-y: auto;
    box-sizing: border-box;
  }

  .drawerDiv h2 {
    text-align: center;
    font-size: 20px;
    margin: 20px 0;
  }

  .drawerDiv p {
    font-size: 16px;
    color: #000000;
    margin-top: 10px;
  }

  .drawerDiv p label {
    font-size: 16px;
    vertical-align: middle;
    font-weight: 600;
    display: inline-block;
    width: 80px;
    text-align: right;
  }

  .drawerDiv p span {
    font-size: 14px;
    vertical-align: middle;
    color: #555555;
    margin-left: 5px;
  }

  .dialogFormVisibleDiv >>> .el-dialog {
    width: 800px;
  }

  .dialogFormVisibleDiv .el-input {
    width: 550px;
  }

  .el-table-header >>> .el-button {
    float: right;
    height: 40px;
  }
</style>

